<?php
/**
 *
 * Created by PhpStorm.
 * User: Egor <http://gitee.com/seosite>
 * Date: 2018/8/9
 * Time: 上午11:15
 * Updatetime:
 * updater：
 */

namespace WAdmin\Controller;


class FormController extends BaseController
{

    public function __check($start_time, $end_time, $car_no)
    {

        if ($start_time > $end_time) return showErrorMsg('开始时间不能比结束时间大', 100002);

        $uid = $this->userInfo->id;

        if (!empty($car_no)) {
            $carInfo = M('car')->where(['car_no' => $car_no, 'uid' => $uid])->find();

            if (empty($carInfo)) return showErrorMsg(L("_DATA_NOT_EXIT_"), 100002);
        }

        return true;
    }

    /**
     * @desc 里程报表
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function mileage($param)
    {
//        $check = CheckFactoryController::isLogin();
//        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('type');

        unset($check);

        $p = empty($param['p']) ?: $param['p'];
        $listRows = empty($param['listRows']) ? 20 : $param['listRows'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }


        if ($this->__check($start_time, $end_time, '') !== true) return $this->__check($start_time, $end_time, '');


        $model = M('car_attr a');

        $map['a.uid'] = $this->userInfo->id;

        $map['a.create_time'] = array('between', array($start_time, $end_time));

        list($list, $page) = _listPage($model, $map, $p, 'a.create_time desc', 'a.id,a.today_mileage,a.create_time,c.car_no', $listRows, 'c.car_no', 'left join think_car c on c.id = a.car_id');

        return showList($list, $page);
    }


    /**
     * @desc 里程报表详情
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array|bool
     */
    public function mileageDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('car_no,type');

        unset($check);

        $car_no = $param['car_no'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }

        $map['create_time'] = array('between', array($start_time, $end_time));

        $map['car_id'] = M('car')->where(['car_no' => $car_no])->getField('id');

        $model = M('car_attr');

        if ($type == 1) {//日
            $ret = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret)) {
                foreach ($ret as &$val) {
                    //获取当前今日里程
                    $li_map['create_time'] = array('elt', strtotime($val['x']) + 3600);

                    $val['y'] = $model->where($li_map)->order("id desc")->getField("today_mileage");
                }
                unset($val);
            }

        } else {
            $ret = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x")
                ->where($map)
                ->group("x")
                ->select();

            if (!empty($ret)) {
                foreach ($ret as &$val) {
                    //获取当前今日里程
                    $li_map['create_time'] = array('elt', strtotime($val['x']) + 3600 * 24);

                    $val['y'] = $model->where($li_map)->order("id desc")->getField("today_mileage");
                }
                unset($val);
            }

        }

        return showList($ret, new \stdClass());
    }

    /**
     * @desc 定位报表
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function location($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('type');

        unset($check);

        $p = empty($param['p']) ?: $param['p'];
        $listRows = empty($param['listRows']) ? 20 : $param['listRows'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }


        if ($this->__check($start_time, $end_time, '') !== true) return $this->__check($start_time, $end_time, '');


        $model = M('car_attr a');

        $map['a.uid'] = $this->userInfo->id;

        $map['a.create_time'] = array('between', array($start_time, $end_time));

        list($list, $page) = _listPage($model, $map, $p, 'a.create_time desc', 'a.id,a.stop_time,a.create_time,c.car_no', $listRows, 'car_no', 'left join think_car c on c.id = a.car_id');

        return showList($list, $page);

    }

    /**
     * @desc 定位详情
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array|void
     */
    public function locationDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('car_no,type');

        unset($check);

        $car_no = $param['car_no'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }

        $map['create_time'] = array('between', array($start_time, $end_time));

        $map['car_id'] = M('car')->where(['car_no' => $car_no])->getField('id');

        $model = M('car_attr');

        if ($type == 1) {//日
            $ret = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret)) {
                foreach ($ret as &$val) {
                    //获取当前停车时间
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("stop_time");
                }
                unset($val);
            }

        } else {
            $ret = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x,sum(stop_time) y")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret)) {
                foreach ($ret as &$val) {
                    //获取当前停车时间
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600 * 24);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("stop_time");
                }
                unset($val);
            }
        }

        return showList($ret, new \stdClass());
    }

    /**
     * @desc 温湿度报表
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function temAndHum($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('type');

        unset($check);

        $p = empty($param['p']) ?: $param['p'];
        $listRows = empty($param['listRows']) ? 20 : $param['listRows'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }


        if ($this->__check($start_time, $end_time, '') !== true) return $this->__check($start_time, $end_time, '');


        $model = M('car_attr a');

        $map['a.uid'] = $this->userInfo->id;

        $map['a.create_time'] = array('between', array($start_time, $end_time));

        list($list, $page) = _listPage($model, $map, $p, 'a.create_time desc', 'a.id,a.temperature_one,a.temperature_two,a.temperature_three,a.temperature_four,a.humidity_one,a.humidity_two,a.humidity_three,a.humidity_four,a.create_time,c.car_no', $listRows, 'car_no', 'left join think_car c on c.id = a.car_id');

        return showList($list, $page);

    }

    /**
     * @desc 温湿度报表详情
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array|void
     */
    public function temAndHumDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('car_no,type');

        unset($check);

        $car_no = $param['car_no'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }

        $map['create_time'] = array('between', array($start_time, $end_time));

        $car_id = M('car')->where(['car_no' => $car_no])->getField('id');

        $map['car_id'] = $car_id;

        $model = M('car_attr');

        $equipment = M("car_equipment")->where(['car_id' => $car_id])->find();


        //  a.temperature_one,a.temperature_two,a.temperature_three,a.temperature_four,a.humidity_one,a.humidity_two,a.humidity_three,a.humidity_four


        if ($type == 1) {//日
            $ret1 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->where($map)
                ->group("x")
                ->select();

            if (!empty($ret1)) {
                foreach ($ret1 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("temperature_one");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("one_zone_temperature");
                }
                unset($val);
            }

            $ret2 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret2)) {
                foreach ($ret2 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("temperature_two");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("two_zone_temperature");
                }
                unset($val);
            }

            $ret3 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret3)) {
                foreach ($ret3 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("temperature_three");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("three_zone_temperature");
                }
                unset($val);
            }

            $ret4 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret4)) {
                foreach ($ret4 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("temperature_four");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("four_zone_temperature");
                }
                unset($val);
            }

            $ret5 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret5)) {
                foreach ($ret5 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("humidity_one");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("one_zone_humidity");
                }
                unset($val);
            }

            $ret6 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret6)) {
                foreach ($ret6 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("humidity_two");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("two_zone_humidity");
                }
                unset($val);
            }

            $ret7 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret7)) {
                foreach ($ret7 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("humidity_three");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("three_zone_humidity");
                }
                unset($val);
            }

            $ret8 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret8)) {
                foreach ($ret8 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("humidity_four");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("four_zone_humidity");
                }
                unset($val);
            }

        } else {
            $ret1 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret1)) {
                foreach ($ret1 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600 * 24);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("temperature_one");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("one_zone_temperature");
                }
                unset($val);
            }

            $ret2 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret2)) {
                foreach ($ret2 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600 * 24);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("temperature_two");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("two_zone_temperature");
                }
                unset($val);
            }

            $ret3 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret3)) {
                foreach ($ret3 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600 * 24);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("temperature_three");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("three_zone_temperature");
                }
                unset($val);
            }

            $ret4 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret4)) {
                foreach ($ret4 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600 * 24);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("temperature_four");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("four_zone_temperature");
                }
                unset($val);
            }

            $ret5 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret5)) {
                foreach ($ret5 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600 * 24);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("humidity_one");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("one_zone_humidity");
                }
                unset($val);
            }

            $ret6 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret6)) {
                foreach ($ret6 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600 * 24);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("humidity_two");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("two_zone_humidity");
                }
                unset($val);
            }

            $ret7 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret7)) {
                foreach ($ret7 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600 * 24);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("humidity_three");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("three_zone_humidity");
                }
                unset($val);
            }

            $ret8 = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x")
                ->where($map)
                ->group("x")
                ->select();
            if (!empty($ret8)) {
                foreach ($ret8 as &$val) {
                    //获取当前温度
                    $stop_map['create_time'] = array('elt', strtotime($val['x']) + 3600 * 24);
                    $val['y'] = $model->where($stop_map)->order("id desc")->getField("humidity_four");
                    $val['area'] = M('car_equipment')->where(['car_id' => $car_id])->getField("four_zone_humidity");
                }
                unset($val);
            }


        }

//        $t1 = M('user_equipment')->where(['uid'=>$this->userInfo->id,'equipment_id'=>20])->find();
//        $s1 = M('user_equipment')->where(['uid'=>$this->userInfo->id,'equipment_id'=>21])->find();
//        $t2 = M('user_equipment')->where(['uid'=>$this->userInfo->id,'equipment_id'=>22])->find();
//        $s2 = M('user_equipment')->where(['uid'=>$this->userInfo->id,'equipment_id'=>23])->find();
//        $t3 = M('user_equipment')->where(['uid'=>$this->userInfo->id,'equipment_id'=>24])->find();
//        $s3 = M('user_equipment')->where(['uid'=>$this->userInfo->id,'equipment_id'=>25])->find();
//        $t4 = M('user_equipment')->where(['uid'=>$this->userInfo->id,'equipment_id'=>26])->find();
//        $s4 = M('user_equipment')->where(['uid'=>$this->userInfo->id,'equipment_id'=>27])->find();

        $ret_data = [
            't1' => $ret1,
            't2' => $ret2,
            't3' => $ret3,
            't4' => $ret4,
            's1' => $ret5,
            's2' => $ret6,
            's3' => $ret7,
            's4' => $ret8,
//            's1'=>$s1,
//            's2'=>$s2,
//            's3'=>$s3,
//            's4'=>$s4,
//            't1'=>$t1,
//            't2'=>$t2,
//            't3'=>$t3,
//            't4'=>$t4,
//            'template'=>empty($equipment['temperature'])?0:$equipment['temperature'],
//            'humidity'=>empty($equipment['humidity'])?0:$equipment['humidity'],
        ];
        return showList($ret_data, new \stdClass());

    }

    /**
     * @desc 冷机运行报表
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function coldCar($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('start_time,end_time');

        unset($check);

        $p = empty($param['p']) ?: $param['p'];
        $listRows = empty($param['listRows']) ? 20 : $param['listRows'];

        $start_time = strtotime($param['start_time']);
        $end_time = strtotime($param['end_time']);

//        $type = $param['type'];
//
//        switch ($type){
//            case 1://今日
//
//                $start_time = strtotime(date('Y-m-d'));
//                $end_time   = time();
//
//                break;
//
//            case 2://本周
//
//                $start_time = mktime(0,0,0,date('m'),date('d')-date('w')+1,date('y'));
//                $end_time   = time();
//
//
//                break;
//
//            case 3://本月
//
//                $start_time = mktime(0,0,0,date('m'),1,date('Y'));
//                $end_time   = mktime(23,59,59,date('m'),date('t'),date('Y'));
//
//                break;
//            default:
//                return;
//        }


        if ($this->__check($start_time, $end_time, '') !== true) return $this->__check($start_time, $end_time, '');


        $model = M('car_attr a');

        $map['a.uid'] = $this->userInfo->id;

        $map['a.create_time'] = array('between', array($start_time, $end_time));

        list($list, $page) = _listPage($model, $map, $p, 'a.create_time desc', 'a.id,a.cold_switch,a.create_time,c.car_no', $listRows, 'car_no', 'left join think_car c on c.id = a.car_id');

        return showList($list, $page);
    }

    /**
     * @desc 冷机运行详情报表
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array|void
     */
    public function coldCarDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('car_no,start_time');

        unset($check);

        $car_no = $param['car_no'];

        $start_time = strtotime($param['start_time']);

        //7天限定
        $end_time = $start_time + 7 * (3600 * 24);
        $map['create_time'] = array('between', array($start_time, $end_time));

        $map['car_id'] = M('car')->where(['car_no' => $car_no])->getField('id');

        $model = M('car_attr');

        $ret = $model
            ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x,create_time,create_time j")
            ->where($map)
            ->group("x")
            ->select();
        $returnDate=[];

        if (!empty($ret)) {
            foreach ($ret as &$val) {
                $val['create_time'] = date('l', $val['create_time']);
                $val['y'] = $model->where(['create_time' => array('elt', strtotime($val['create_time']) + 3600)])->order("id desc")->getField("cold_switch");
                $val['j']=date('H',$val['j']);


                if ($val['create_time']=="Monday"){
                    if ($val['j']=='01'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time']=="Tuesday"){
                    if ($val['j']=='01'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time']=="Wednesday"){
                    if ($val['j']=='01'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time']=="Thursday"){
                    if ($val['j']=='01'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time']=="Friday"){
                    if ($val['j']=='01'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time']=="Saturday"){
                    if ($val['j']=='01'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time']=="Sunday"){
                    if ($val['j']=='01'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate[$val['create_time']][$val['j']]=$val['y'];
                    }
                }

            }
        }


        return showList($returnDate, new \stdClass());
    }


    /**
     * @desc 门禁报表
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function door($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('start_time,end_time');

        unset($check);

        $p = empty($param['p']) ?: $param['p'];
        $listRows = empty($param['listRows']) ? 20 : $param['listRows'];

        $start_time = strtotime($param['start_time']);
        $end_time = strtotime($param['end_time']);

//        $type = $param['type'];
//
//        switch ($type){
//            case 1://今日
//
//                $start_time = strtotime(date('Y-m-d'));
//                $end_time   = time();
//
//                break;
//
//            case 2://本周
//
//                $start_time = mktime(0,0,0,date('m'),date('d')-date('w')+1,date('y'));
//                $end_time   = time();
//
//
//                break;
//
//            case 3://本月
//
//                $start_time = mktime(0,0,0,date('m'),1,date('Y'));
//                $end_time   = mktime(23,59,59,date('m'),date('t'),date('Y'));
//
//                break;
//            default:
//                return;
//        }
//

        if ($this->__check($start_time, $end_time, '') !== true) return $this->__check($start_time, $end_time, '');


        $model = M('car_attr a');

        $map['a.uid'] = $this->userInfo->id;

        $map['a.create_time'] = array('between', array($start_time, $end_time));

        list($list, $page) = _listPage($model, $map, $p, 'a.create_time desc', 'a.id,a.door,a.create_time,c.car_no', $listRows, 'car_no', 'left join think_car c on c.id = a.car_id');

        return showList($list, $page);
    }


    /**
     * @desc 门禁报表详情
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array|void
     */
    public function doorDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('car_no,start_time');

        unset($check);

        $car_no = $param['car_no'];

        $start_time = strtotime($param['start_time']);

        //7天限定
        $end_time = $start_time + 7 * (3600 * 24);
        $map['create_time'] = array('between', array($start_time, $end_time));

        $map['car_id'] = M('car')->where(['car_no' => $car_no])->getField('id');

        $model = M('car_attr');

        $ret = $model
            ->field("from_unixtime(create_time,'%Y/%m/%d %H') x,create_time,create_time j")
            ->where($map)
            ->group("x")
            ->select();
        $returnDate = [];
        if (!empty($ret)) {
            foreach ($ret as &$val) {
                $val['create_time'] = date('l', $val['create_time']);
                $val['y'] = $model->where(['create_time' => array('elt', strtotime($val['create_time']) + 3600)])->order("id desc")->getField("door");
                $val['j']=date('H',$val['j']);

                if ($val['create_time'] == "Monday") {
                    if ($val['j']=='01'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate['Monday'][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time'] == "Tuesday") {
                    if ($val['j']=='01'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate['Tuesday'][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time'] == "Wednesday") {
                    if ($val['j']=='01'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate['Wednesday'][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time'] == "Thursday") {
                    if ($val['j']=='01'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate['Thursday'][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time'] == "Friday") {
                    if ($val['j']=='01'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate['Friday'][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time'] == "Saturday") {
                    if ($val['j']=='01'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate['Saturday'][$val['j']]=$val['y'];
                    }
                }
                if ($val['create_time'] == "Sunday") {
                    if ($val['j']=='01'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='02'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='03'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='04'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='05'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='06'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='07'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='08'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='09'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='10'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='11'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='12'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='13'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='14'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='15'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='16'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='17'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='18'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='19'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='20'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='21'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='22'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='23'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                    if ($val['j']=='24'){
                        $returnDate['Sunday'][$val['j']]=$val['y'];
                    }
                }
            }
        }


        return showList($returnDate, new \stdClass());
    }

    /**
     * @desc 围栏报表
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function enclosure($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('type');

        unset($check);

        $p = empty($param['p']) ?: $param['p'];
        $listRows = empty($param['listRows']) ? 20 : $param['listRows'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }


        if ($this->__check($start_time, $end_time, '') !== true) return $this->__check($start_time, $end_time, '');


        $model = M('car_enclosure a');

        $map['a.uid'] = $this->userInfo->id;

        $map['a.outtime'] = array('between', array($start_time, $end_time));

        list($list, $page) = _listPage($model, $map, $p, 'a.outtime desc', 'a.id,a.intime,a.outtime,c.car_no,count(a.id) counts', $listRows, 'car_no', 'left join think_car c on c.id = a.car_id');

        return showList($list, $page);

    }


    /**
     * @desc 围栏详情
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array|void
     */
    public function enclosureDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('car_no,type');

        unset($check);

        $car_no = $param['car_no'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }

        $map['outtime'] = array('between', array($start_time, $end_time));

        $map['car_id'] = M('car')->where(['car_no' => $car_no])->getField('id');

        $model = M('car_enclosure');

        if ($type == 1) {//日
            $ret = $model
                ->field("from_unixtime(outtime,'%Y/%m/%d %H:00') x,count(*) y")
                ->where($map)
                ->group("x")
                ->select();

        } else {
            $ret = $model
                ->field("from_unixtime(outtime,'%Y/%m/%d') x,count(*) y")
                ->where($map)
                ->group("x")
                ->select();
        }

        return showList($ret, new \stdClass());
    }


    /**
     * @desc 停车报表
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function park($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('type');

        unset($check);

        $p = empty($param['p']) ?: $param['p'];
        $listRows = empty($param['listRows']) ? 20 : $param['listRows'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }


        if ($this->__check($start_time, $end_time, '') !== true) return $this->__check($start_time, $end_time, '');


        $model = M('car_attr a');

        $map['a.uid'] = $this->userInfo->id;
        $map['a.stop_time'] = array('gt', 0);

        $map['a.create_time'] = array('between', array($start_time, $end_time));

        if ($type == 1) {//日
            list($list, $page) = _listPage($model, $map, $p, 'a.create_time desc', 'a.id,a.stop_time,a.create_time,c.car_no', $listRows, 'car_no', 'left join think_car c on c.id = a.car_id');

            if (!empty($list)) {
                foreach ($list as &$val) {
                    $stop_info = explode(',', $val['stop_time']);
                    $num = 0;
                    for ($i = 0; $i < count($stop_info); $i++) {
                        if ($stop_info[$i] > $stop_info[$i + 1]) {
                            $num++;
                        }
                    }
                    $val['stop_num'] = $num;
                }
            }


        } elseif ($type == 2) {//周
            list($list, $page) = _listPage($model, $map, $p, "a.create_time desc", "a.id,group_concat(a.stop_time) stop_time,c.car_no,FROM_UNIXTIME(a.create_time,'%Y-%m-%d') create_time", $listRows, 'car_no', 'left join think_car c on c.id = a.car_id');

            if (!empty($list)) {
                foreach ($list as &$val) {
                    $stop_info = explode(',', $val['stop_time']);
                    $num = 0;
                    for ($i = 0; $i < count($stop_info); $i++) {
                        if ($stop_info[$i] > $stop_info[$i + 1]) {
                            $num++;
                        }
                    }
                    $val['stop_num'] = $num;
                }
            }


        } else {
            list($list, $page) = _listPage($model, $map, $p, "a.create_time desc", "a.id,group_concat(a.stop_time) stop_time,c.car_no,FROM_UNIXTIME(a.create_time,'%Y-%m-%d') create_time", $listRows, 'car_no', 'left join think_car c on c.id = a.car_id');

            if (!empty($list)) {
                foreach ($list as &$val) {
                    $stop_info = explode(',', $val['stop_time']);
                    $num = 0;
                    for ($i = 0; $i < count($stop_info); $i++) {
                        if ($stop_info[$i] > $stop_info[$i + 1]) {
                            $num++;
                        }
                    }
                    $val['stop_num'] = $num;
                }
            }

        }

        return showList($list, $page);

    }


    /**
     * @desc 停车报表详情
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array|void
     */
    public function parkDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('car_no,type');

        unset($check);

        $car_no = $param['car_no'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }

        $map['create_time'] = array('between', array($start_time, $end_time));

        $map['car_id'] = M('car')->where(['car_no' => $car_no])->getField('id');

        $map['stop_time'] = array('gt', 0);
        $model = M('car_attr');

        if ($type == 1) {//日
            $ret = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->where($map)
                ->group("x")
                ->select();
            $num = 0;
            if (!empty($ret)) {
                foreach ($ret as &$val) {
                    //计算停车次数

                    //获取该时间内停车时间大于0的数据
                    $infoStop = $model->where(['create_time' => array('between', array(strtotime($val['x']), strtotime($val['x']) + 3600))])->getField("stop_time", true);

                    if (!empty($infoStop)) {
                        for ($i = 0; $i < count($infoStop); $i++) {
                            if ($infoStop[$i] > $infoStop[$i + 1]) {
                                $num++;
                            }
                        }
                    } else {
                        $num = 0;
                    }

                    $val['y'] = $num;
                }
            }


        } else {
            $ret = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x")
                ->where($map)
                ->group("x")
                ->select();

            $num = 0;
            if (!empty($ret)) {
                foreach ($ret as &$val) {
                    //计算停车次数

                    //获取该时间内停车时间大于0的数据
                    $infoStop = $model->where(['create_time' => array('between', array(strtotime($val['x']), strtotime($val['x']) + 3600 * 24))])->getField("stop_time", true);

                    if (!empty($infoStop)) {
                        for ($i = 0; $i < count($infoStop); $i++) {
                            if ($infoStop[$i] > $infoStop[$i + 1]) {
                                $num++;
                            }
                        }
                    } else {
                        $num = 0;
                    }

                    $val['y'] = $num;
                }
            }

        }

        return showList($ret, new \stdClass());
    }

    /**
     * @desc 油量报表
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function oil($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('type');

        unset($check);

        $p = empty($param['p']) ?: $param['p'];
        $listRows = empty($param['listRows']) ? 20 : $param['listRows'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }


        if ($this->__check($start_time, $end_time, '') !== true) return $this->__check($start_time, $end_time, '');


        $model = M('car_attr a');

        $map['a.uid'] = $this->userInfo->id;

        $map['a.create_time'] = array('between', array($start_time, $end_time));

        list($list, $page) = _listPage($model, $map, $p, 'a.create_time desc', 'a.id,a.oil,a.create_time,c.car_no', $listRows, 'car_no', 'left join think_car c on c.id = a.car_id');

        return showList($list, $page);
    }


    /**
     * @desc 油量报表详情
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array|void
     */
    public function oilDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('car_no,type');

        unset($check);

        $car_no = $param['car_no'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }

        $map['create_time'] = array('between', array($start_time, $end_time));

        $map['car_id'] = M('car')->where(['car_no' => $car_no])->getField('id');

        $model = M('car_attr');

        if ($type == 1) {//日
            $ret = $model
                ->where($map)
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x")
                ->group("x")
                ->select();
            if (!empty($ret)) {
                foreach ($ret as &$val) {
                    $oil_map['create_time'] = array('elt', strtotime($val['x']) + 3600);
                    $val['y'] = $model->where($oil_map)->order("id desc")->getField("oil");
                }
            }

        } else {
            $ret = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x")
                ->where($map)
                ->group("x")
                ->select();

            if (!empty($ret)) {
                foreach ($ret as &$val) {
                    $oil_map['create_time'] = array('elt', strtotime($val['x']) + 3600 * 24);
                    $val['y'] = $model->where($oil_map)->order("id desc")->getField("oil");
                }
            }

        }

//        if (!empty($ret)){
//            foreach ($ret as &$val){
//                $val['x']=empty($val['x'])?0:date('Y/m/d H:i:s',$val['x']);
//            }
//        }

        return showList($ret, new \stdClass());
    }


    /**
     * @desc 警告报表
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function warning($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('type');

        unset($check);

        $p = empty($param['p']) ?: $param['p'];
        $listRows = empty($param['listRows']) ? 20 : $param['listRows'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }


        if ($this->__check($start_time, $end_time, '') !== true) return $this->__check($start_time, $end_time, '');


        $model = M('message a');

        $map['a.uid'] = $this->userInfo->id;

        $map['a.create_time'] = array('between', array($start_time, $end_time));

        $map['a.car_id'] = array('gt', 0);
        $map['a.type'] = array('eq', 2);

        list($list, $page) = _listPage($model, $map, $p, 'a.create_time desc', 'count(*) counts,a.content,a.warning_type,a.create_time,c.car_no', $listRows, 'car_id', 'left join think_car c on c.id = a.car_id');

        return showList($list, $page);
    }


    /**
     * @desc 报警报表详情
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array|void
     */
    public function warningDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('car_no,type');

        unset($check);

        $car_no = $param['car_no'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }

        $map['create_time'] = array('between', array($start_time, $end_time));

        $map['car_id'] = M('car')->where(['car_no' => $car_no])->getField('id');

        $model = M('message');

        if ($type == 1) {//日
            $ret = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x,count(*) y")
                ->where($map)
                ->group("x")
                ->select();

        } else {
            $ret = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x,count(*) y")
                ->where($map)
                ->group("x")
                ->select();
        }

        return showList($ret, new \stdClass());
    }

    /**
     * @desc 汇总报表
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array
     */
    public function summary($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('type');

        unset($check);

        $p = empty($param['p']) ?: $param['p'];
        $listRows = empty($param['listRows']) ? 20 : $param['listRows'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }


        if ($this->__check($start_time, $end_time, '') !== true) return $this->__check($start_time, $end_time, '');


        $model = M('car_attr a');

        $map['a.uid'] = $this->userInfo->id;

        $map['a.create_time'] = array('between', array($start_time, $end_time));

        list($list, $page) = _listPage($model, $map, $p, 'a.create_time desc', 'a.id,a.car_id,a.speed,a.lng,a.lat,a.temperature_one_area,a.temperature_two_area,a.temperature_three_area,a.temperature_four_area,a.humidity_one,a.humidity_two,a.humidity_three,a.humidity_four,a.cold_switch,a.today_mileage,a.create_time,c.car_no', $listRows, 'car_no', 'left join think_car c on c.id = a.car_id');

        if (!empty($list)) {
            foreach ($list as &$val) {
                $val['create_time'] = date('Y/m/d H:i:s', $val['create_time']);
                $door_map['door'] = 2;
                $door_map['car_id'] = $val['car_id'];
                $door_map['uid'] = $this->userInfo->id;
                $door_map['create_time'] = array('between', array($start_time, $end_time));
                $door_sum = M('car_attr')->where($door_map)->count();
                $val['door_sum'] = empty($door_sum) ? 0 : $door_sum;
            }
        }

        return showList($list, $page);

    }

    /**
     * @desc 汇总报表详情
     * @author Egor<http://gitee.com/seosite>
     * @param $param
     * @return array|void
     */
    public function summaryDetail($param)
    {
        $check = CheckFactoryController::isLogin();
        $check->before($param);

        $check = CheckFactoryController::isParamSet();
        $check->before($param);

        $check = CheckFactoryController::isChildParamSet();
        $check->before('car_no,type');

        unset($check);

        $car_no = $param['car_no'];

        $type = $param['type'];

        switch ($type) {
            case 1://今日

                $start_time = strtotime(date('Y-m-d'));
                $end_time = time();

                break;

            case 2://本周

                $start_time = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
                $end_time = time();


                break;

            case 3://本月

                $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
                $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));

                break;
            default:
                return;
        }

        $map['create_time'] = array('between', array($start_time, $end_time));

        $map['car_id'] = M('car')->where(['car_no' => $car_no])->getField('id');

        $model = M('car_enclosure');

        if ($type == 1) {//日
            $ret = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d %H:00') x,stop_time y")
                ->where($map)
                ->group("x")
                ->select();

        } else {
            $ret = $model
                ->field("from_unixtime(create_time,'%Y/%m/%d') x,stop_time y")
                ->where($map)
                ->group("x")
                ->select();
        }

        return showList($ret, new \stdClass());
    }

}